//
//  UIBarButtonItem+Extension.swift
//  weibo
//
//  Created by afan on 16/3/26.
//  Copyright © 2016年 阿范. All rights reserved.
//

import UIKit
extension UIBarButtonItem{
    convenience init(imageName: String, target: AnyObject?, action: Selector) {
        // 1.自己调用指定构造函数
        //        super.init()
        let button = UIButton()
        button.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        button.setImage(UIImage(named: "\(imageName)_highlighted"), forState: UIControlState.Highlighted)
        button.sizeToFit()
        
        // 按钮添加点击事件
        button.addTarget(target, action: action, forControlEvents: UIControlEvents.TouchUpInside)
        
        // 2.也可以调用self的便利构造函数,实际上内容它调用了指定构造函数
        self.init(customView: button)
    }
}
